package corbaServer.corba;

import java.util.List;
import corbaServer.dao.*;

public class CorbaServer extends ICorbaServerPOA
{
	String server;
	
	public CorbaServer(String s)
	{
		server = s;
	}

	@Override
	public EventDTO[] getEvents()
	{
		CorbaEventServerDAO corbaEventServerDAO = null;
		
		if (server.equals("Madrid"))
		{
			corbaEventServerDAO = new MadridCorbaEventServerDAO();
		}
		else if (server.equals("Bilbao"))
		{
			corbaEventServerDAO = new BilbaoCorbaEventServerDAO();
		}
		
		List<corbaServer.EventDO> listEventDTO = corbaEventServerDAO.getEvents();
		
		EventDTO[] arrayEventDTO = new EventDTO[listEventDTO.size()];
		
		for (int i = 0; i < listEventDTO.size(); i++)
		{
			arrayEventDTO[i] = new EventDTO(listEventDTO.get(i).getName(), listEventDTO.get(i).getDate(), listEventDTO.get(i).getDescription(), listEventDTO.get(i).getPlaces());
		}
		
		return arrayEventDTO;
	}

}
